package com.myweixin.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import com.jfinal.core.JFinalFilter;

/**
 * JFinal framework filter
 */
public final class WeiXinFilter implements Filter {

	JFinalFilter jFinalFilter = new JFinalFilter();

	public void init(FilterConfig filterConfig) throws ServletException {
		jFinalFilter.init(filterConfig);
	}

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;

		String uri = request.getPathInfo();
		if (uri.startsWith("/wx/"))
			jFinalFilter.doFilter(req, res, chain);
		else
			chain.doFilter(req, res);
	}

	public void destroy() {
		jFinalFilter.destroy();
	}

}
